import org.apache.commons.io.IOUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by dllo on 18/5/11.
 */
/*
可以通过注解的形式
来配置servlet的名字和路径
这种写法 就不需要去web.xml中 注册了
效果和写在 web.xml中是一致的
 */
@WebServlet(name = "DWServlet" ,urlPatterns = "/error404")
public class DWServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
//                response.getWriter().println("hello world");
        ServletContext app =getServletContext();
        InputStream is= app.getResourceAsStream("Error404.html");
        String html = IOUtils.toString(is,"utf8");
        response.getWriter().println(html);
        is.close();
    }
}
